package com.longcai.piaojia.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

/**
 * Created by Administrator on 2015/12/22.
 */
public class DashedHorizontalLineView extends TextView {


    public DashedHorizontalLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        DisplayMetrics dm = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(ContextCompat.getColor(getContext(), R.color.light_line_color));//颜色可以自己设置
        Path path = new Path();
        path.moveTo(0, 0);//起始坐标
        path.lineTo(0, dm.heightPixels);//终点坐标
        PathEffect effects = new DashPathEffect(new float[]{ScaleScreenHelperFactory.getInstance().getWidthHeight(6), ScaleScreenHelperFactory.getInstance().getWidthHeight(2), ScaleScreenHelperFactory.getInstance().getWidthHeight(6), ScaleScreenHelperFactory.getInstance().getWidthHeight(2)}, ScaleScreenHelperFactory.getInstance().getWidthHeight(1));//设置虚线的间隔和点的长度
        paint.setPathEffect(effects);
        canvas.drawPath(path, paint);
    }
}
